package edu.ciee.tz.dao;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import edu.ciee.tz.model.McysJiaob;

@Component("mcysjiaobDao")
public class McysJiaobDAO {

	public List<McysJiaob> search(McysJiaob g) throws Exception {

		String query = "where 1=1";

		if (g.getId() != 0) 
			query = query + " and id like '%" + g.getId() + "%'";// this.getID()
		if (g.getWeight() != null) 
			query = query + " and weight like '%" + g.getWeight()+ "%'";// this.getID()
		if (g.getJiaobiao_id() != null) 
			query = query + " and jiaobiao_id like '%" + g.getJiaobiao_id()+ "%'";// this.getID()
		if (g.getMcys_id()!=null&&g.getMcys_id().getId()!= 0) 
			query = query + " and mcys_id like '%" + g.getMcys_id().getId()+ "%'";// this.getID()
		@SuppressWarnings("unchecked")
		List<McysJiaob> m_list = hibernateTemplate.find("from McysJiaob u "+ query);

		return m_list;
	}

	public void insert(McysJiaob z) throws Exception {
		this.getHibernateTemplate().save(z);
	}

	public void delete(McysJiaob z) throws Exception {
		this.getHibernateTemplate().delete(z);

	}

	public void update(McysJiaob z) throws Exception {
		this.getHibernateTemplate().update(z);
	}

	private HibernateTemplate hibernateTemplate;

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
}
